package com.zzyl.nursing.controller;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.FamilyMemberElderPageDto;
import com.zzyl.nursing.dto.MyFamilyDto;
import com.zzyl.nursing.dto.QueryDeviceDataDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.FamilyMemberElderService;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.BindingFamilyVo;
import com.zzyl.nursing.vo.DeviceShadowVo;
import com.zzyl.nursing.vo.HeartRateVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 *
 * @author hypo
 * @date 2025-08-01
 */
@Tag(name = "老人家属")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private FamilyMemberElderService familyMemberElderService;

    @Autowired
    private IDeviceService deviceService;

    @Autowired
    private IDeviceDataService deviceDataService;

    /**
     *按周统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @Operation(description = "按周统计查询指标数据")
    public AjaxResult queryDeviceDataListByWeek(QueryDeviceDataDto dto){
        List<HeartRateVo> heartRateVos = deviceDataService.queryDeviceDataList(dto);
        return success(heartRateVos);
    }
    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    @Operation(description = "按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(QueryDeviceDataDto dto) {
        List<HeartRateVo> heartRateVos = deviceDataService.queryDeviceDataList(dto);
        return success(heartRateVos);
    }

    /**
     * 查询健康数据
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @Operation(description = "查询健康数据")
    public AjaxResult queryServiceProperties(@PathVariable("iotId") String iotId) {
        List<DeviceShadowVo> deviceShadowVos = deviceService.queryServiceProperties(iotId);
        return AjaxResult.success(deviceShadowVos);
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    @Operation(description = "小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     * 绑定老人
     */
    @PostMapping("/add")
    @Operation(description = "添加老人家属")
    public AjaxResult bindingFamily(@RequestBody BindingFamilyVo vo) {
        familyMemberElderService.bindingFamily(vo);
        return success();
    }

    /**
     * 查询我的家属分页
     */
    @GetMapping("/my")
    @Operation(description = "查询家人列表")
    public R<List<MyFamilyDto>> myFamilyQueryPage(Integer pageNum, Integer pageSize) {
        List<MyFamilyDto> myFamily = familyMemberElderService.myFamilyQueryPage(pageNum, pageSize);
        return R.ok(myFamily);
    }

    /**
     * 查看家人列表分页查询
     */
    @GetMapping("/list-by-page")
    @Operation(description = "分页查询家人列表")
    public R<List<FamilyMemberElderPageDto>> listByPage(Integer pageNum, Integer pageSize) {
        List<FamilyMemberElderPageDto> list = familyMemberElderService.getPageList(pageNum, pageSize);
        return R.ok(list);
    }

}
